<%-- 
    Document   : index
    Created on : 25/05/2013, 12:08:24
    Author     : MauroH
--%>
<%@page import="util.Month"%>
<%@page import="java.util.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8" language="java"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<fmt:message key="system.month1" var="month1"/>
<fmt:message key="system.month2" var="month2"/>
<fmt:message key="system.month3" var="month3"/>
<fmt:message key="system.month4" var="month4"/>
<fmt:message key="system.month5" var="month5"/>
<fmt:message key="system.month6" var="month6"/>
<fmt:message key="system.month7" var="month7"/>
<fmt:message key="system.month8" var="month8"/>
<fmt:message key="system.month9" var="month9"/>
<fmt:message key="system.month10" var="month10"/>
<fmt:message key="system.month11" var="month11"/>
<fmt:message key="system.month12" var="month12"/>

<%@ include file="calendarCommon.jsp" %>
<c:if test="${not empty param.idioma}">
    <fmt:setLocale value="${param.idioma}" scope="session"/>
</c:if>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title><fmt:message key="system.title1"/></title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <!-- Loading Bootstrap -->
        <link href="assets/bootstrap/css/bootstrap.css" rel="stylesheet">
        <link href="assets/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
        <link href="assets/bootstrap/css/prettify.css" rel="stylesheet">

        <!-- Loading Flat UI -->
        <link href="assets/css/flat-ui.css" rel="stylesheet">
        <link href="assets/css/custom.css" rel="stylesheet">

        <link rel="shortcut icon" href="assets/images/favicon.ico">

        <!-- HTML5 shim, for IE6-8 support of HTML5 elements. All other JS at the end of file. -->
        <!--[if lt IE 9]>
          <script src="assets/js/html5shiv.js"></script>
        <![endif]-->
        
    </head>
    <body>
        <div class="container">
            <div class="head row-fluid">
                <div class="span3">
                    <h1><a href="/Agendou/agenda"><fmt:message key="system.title1"/></a></h1>
                </div>
                <div class="span5 offset4">
                    <div class="navbar navbar-inverse">
                        <div class="navbar-inner">
                            <div class="container">
                                <a href="#" class="menu" data-toggle="collapse" data-target="#nav-collapse-01" >
                                    <span><fmt:message key="system.menu0"/></span>
                                    <div class="btn btn-navbar">
                                        <span class="icon-bar"></span>
                                        <span class="icon-bar"></span>
                                        <span class="icon-bar"></span>
                                    </div>
                                </a>
                                <div class="nav-collapse collapse" id="nav-collapse-01">
                                    <ul class="nav">
                                        <c:choose>
                                            <c:when test="${fn:trim(usuario.cpf) != null and fn:trim(usuario.cpf) != ''}">
                                                <li class="active">
                                                    <a href="/Agendou/agenda">
                                                        <fmt:message key="system.menu1"/>
                                                    </a>
                                                </li>
                                                <li>
                                                    <c:choose>
                                                        <c:when test="${usuario.is_admin == true}">
                                                            
                                                            <a href="#fakelink">
                                                                <fmt:message key="system.menu6"/>
                                                            </a>
                                                            <ul>
                                                                <li>
                                                                    <a href="cadHorarios.jsp"><fmt:message key="system.menu7"/></a>
                                                                </li>
                                                                <li>
                                                                    <a href="#fakelink"><fmt:message key="system.menu8"/></a>
                                                                </li>
                                                                <li>
                                                                    <a href="#fakelink"><fmt:message key="system.menu9"/></a>
                                                                </li>
                                                                <li>
                                                                     <c:choose>
                                                                        <c:when test="${param.idioma == 'pt' || param.idioma == null}">
                                                                            <a href="?idioma=en"><fmt:message key="system.menu13"/></a>
                                                                        </c:when>
                                                                        <c:otherwise>
                                                                            <a href="?idioma=pt"><fmt:message key="system.menu12"/></a>
                                                                        </c:otherwise>
                                                                    </c:choose>
                                                                </li>
                                                            </ul>
                                                            
                                                        </c:when>
                                                        <c:otherwise>
                                                            <a href="#fakelink">
                                                                <fmt:message key="system.menu2"/>
                                                            </a>
                                                            <ul>
                                                                <li>
                                                                    <a href="#"><fmt:message key="system.menu11"/></a>
                                                                </li>
                                                                <li>
                                                                    <c:choose>
                                                                        <c:when test="${param.idioma == 'pt' || param.idioma == null}">
                                                                            <a href="?idioma=en"><fmt:message key="system.menu13"/></a>
                                                                        </c:when>
                                                                        <c:otherwise>
                                                                            <a href="?idioma=pt"><fmt:message key="system.menu12"/></a>
                                                                        </c:otherwise>
                                                                    </c:choose>
                                                                    
                                                                </li>
                                                            </ul>
                                                        </c:otherwise>
                                                    </c:choose>
                                                </li>
                                                <li>
                                                    <a href="/Agendou/agenda?cmd=logout">
                                                        <fmt:message key="system.menu5"/>
                                                    </a>
                                                </li>
                                            </c:when>
                                            <c:otherwise>
                                                <li class="active">
                                                    <a href="/Agendou/agenda">
                                                        <fmt:message key="system.menu10"/>
                                                    </a>
                                                </li>
                                                <li>
                                                    <a href="login.jsp">
                                                        <fmt:message key="system.menu3"/>
                                                    </a>
                                                </li>
                                                <li>
                                                    <a href="cadastro.jsp">
                                                        <fmt:message key="system.menu4"/>
                                                    </a>
                                                </li>
                                            </c:otherwise>
                                    </c:choose>
                                    </ul>
                                </div><!--/.nav -->
                            </div>
                        </div>
                    </div>
                </div>
            </div> <!-- /row -->
            <hr />
            <div class="span6 menu2">
                <div class="page-info row-fluid">
                    <div class="navbar navbar-inverse">
                        <div class="navbar-inner">
                            <div class="container">
                                <ul class="nav">
                                    <li class="active">
                                        <a href="index.jsp" class="forever-alone">
                                            <fmt:message key="system.title2"/>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="clearfix"></div>
            
            <div class="calendar row-fluid">
                <ul class="month-browser">
                    <li class="calendar_nav" >
                        &laquo; <a href="?mes=<%=prevMonth%>&ano=<%=prevYear%>"><%=prevName%></a>
                    </li>
                    <li id="current-month">
                        <h2><%=monthName%></h2>
                    </li>
                    <li class="calendar_nav">
                        <a href="?mes=<%=nextMonth%>&ano=<%=nextYear%>"><%=nextName%></a> &raquo;
                    </li>
                </ul>
                <div class="span12">
                    <div class="navbar navbar-inverse">
                        <div class="navbar-inner">
                            <div class="container">
                                <ul class="nav weekdays">
                                    <li>
                                            <fmt:message key="system.weekday1"/>
                                    </li>
                                    <li>
                                            <fmt:message key="system.weekday2"/>
                                    </li>
                                    <li>
                                            <fmt:message key="system.weekday3"/>
                                    </li>
                                    <li>
                                            <fmt:message key="system.weekday4"/>
                                    </li>
                                    <li>
                                            <fmt:message key="system.weekday5"/>
                                    </li>
                                    <li>
                                            <fmt:message key="system.weekday6"/>
                                    </li>
                                    <li>
                                            <fmt:message key="system.weekday7"/>                                        
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
                <%
                
                  Month aMonth = Month.getMonth( Integer.parseInt(currentMonthString), Integer.parseInt(currentYearString) );
                  int [][] days = aMonth.getDays();
                  for( int i=0; i<aMonth.getNumberOfWeeks(); i++ )
                  {
                    %><ul class="days"><%
                    for( int j=0; j<7; j++ )
                    {
                      if( days[i][j] == 0 )
                      {
                        %>
                            <li class="no-shows calendar-day">
                                <div class="date day_cell"></div>
                            </li>
                        <%
                      }
                      else
                      {
                        // this is "today"
                        if( currentDayInt == days[i][j] && currentMonthInt == aMonth.getMonth() && currentYearInt == aMonth.getYear() )
                        {
                          %>
                            <li class="calendar-day today">
                                <div class="date day_cell"> <span class="month"><%=aMonth.getMonth()%></span> <%=days[i][j]%></div>
                                <c:if test="${!empty listaAgendaDisponivel}"  >
                                    <c:forEach var="horario" items="${listaAgendaDisponivel}">
                                        
                                        <c:set var="eachdata" scope="page">
                                            <%=aMonth.getYear() %>-<% if(aMonth.getMonth() < 10) { out.print("0"); } out.print(aMonth.getMonth()+1); %>-<%=days[i][j] %>
                                        </c:set>
                                        <c:set var="date" value="${eachdata}" />
                                        <c:set var="now" value="<%=new java.util.Date()%>" />
                                        <fmt:parseDate pattern="yyyy-MM-dd" value="${date}" var="parsedStatusDate" />
                                        <fmt:formatDate pattern="yyyy-MM-dd" value="${parsedStatusDate}" var="formattedStatusDate" />
                                        <c:if test="${horario.data == formattedStatusDate && horario.horario > now}"  >
                                            <div class="show-info">
                                                <fmt:formatDate pattern="HH:mm" value="${horario.horario}" var="formattedStatusTime" />
                                                <a href="/Agendou/agenda?cmd=addAgenda&data=${horario.data}&horario=${horario.horario}" class="show-name">${formattedStatusTime}</a>
                                            </div>
                                        </c:if>
                                    </c:forEach>
                                </c:if>
                            </li><%
                        }
                        else
                        {
                          %>
                          <li class="calendar-day <% if(currentDayInt > days[i][j]  && currentMonthInt >= aMonth.getMonth() && currentYearInt >= aMonth.getYear() ){ out.print("out_of_range"); } %>">
                                <div class="date day_cell"> <span class="month"><%=aMonth.getMonth()%></span> <%=days[i][j]%></div>
                                <c:if test="${!empty listaAgendaIndisponivel}"  >
                                    <c:forEach var="horario" items="${listaAgendaIndisponivel}">
                                        <c:set var="eachdata" scope="page">
                                            <%=aMonth.getYear() %>-<% if(aMonth.getMonth() < 10) { out.print("0"); } out.print(aMonth.getMonth()+1); %>-<%=days[i][j] %>
                                        </c:set>
                                        <c:set var="date" value="${eachdata}" />
                                        <fmt:parseDate pattern="yyyy-MM-dd" value="${date}" var="parsedStatusDate" />
                                        <fmt:formatDate pattern="yyyy-MM-dd" value="${parsedStatusDate}" var="formattedStatusDate" />
                                        
                                        <c:if test="${horario.data == formattedStatusDate}"  >
                                            <div class="show-info marked">
                                                <fmt:formatDate pattern="HH:mm" value="${horario.horario}" var="formattedStatusTime" />
                                                <a href="/Agendou/agenda?cmd=visualizarAgenda&idhorario=${horario.idhorarios}" class="show-name">${formattedStatusTime}</a>
                                            </div>
                                        </c:if>
                                    </c:forEach>
                                </c:if>
                                <c:if test="${!empty listaAgendaDisponivel}"  >
                                    <c:forEach var="horario" items="${listaAgendaDisponivel}">
                                        <c:set var="eachdata" scope="page">
                                            <%=aMonth.getYear() %>-<% if(aMonth.getMonth() < 10) { out.print("0"); } out.print(aMonth.getMonth()+1); %>-<%=days[i][j] %>
                                        </c:set>
                                        <c:set var="date" value="${eachdata}" />
                                        <fmt:parseDate pattern="yyyy-MM-dd" value="${date}" var="parsedStatusDate" />
                                        <fmt:formatDate pattern="yyyy-MM-dd" value="${parsedStatusDate}" var="formattedStatusDate" />
                                        
                                        <c:if test="${horario.data == formattedStatusDate}"  >
                                            <% if( currentDayInt <= days[i][j]  && currentMonthInt <= aMonth.getMonth() && currentYearInt <= aMonth.getYear()){ %>
                                                <div class="show-info">
                                                    <fmt:formatDate pattern="HH:mm" value="${horario.horario}" var="formattedStatusTime" />
                                                    <a href="/Agendou/agenda?cmd=addAgenda&data=${horario.data}&horario=${horario.horario}" class="show-name">${formattedStatusTime}</a>
                                                </div>
                                            <% } %>
                                            <% if(currentMonthInt < aMonth.getMonth() && currentYearInt <= aMonth.getYear()) { %>
                                                <div class="show-info">
                                                    <fmt:formatDate pattern="HH:mm" value="${horario.horario}" var="formattedStatusTime" />
                                                    <a href="/Agendou/agenda?cmd=addAgenda&data=${horario.data}&horario=${horario.horario}" class="show-name">${formattedStatusTime}</a>
                                                </div>
                                            <% } %>
                                            <% if(currentYearInt < aMonth.getYear()) { %>
                                                <div class="show-info">
                                                    <fmt:formatDate pattern="HH:mm" value="${horario.horario}" var="formattedStatusTime" />
                                                    <a href="/Agendou/agenda?cmd=addAgenda&data=${horario.data}&horario=${horario.horario}" class="show-name">${formattedStatusTime}</a>
                                                </div>
                                            <% } %>
                                        </c:if>
                                    </c:forEach>
                                </c:if>
                            </li>
                            <%
                        }
                      } // end outer if
                    } // end for
                    %>
                    </ul>
                  <%}
               %>

            </div>
        </div>
        
        <script src="assets/js/jquery-1.8.3.min.js"></script>
        <script src="assets/js/bootstrap.min.js"></script>
    </body>
</html>